package com.laoxiang.modules.system.controller;



import com.laoxiang.modules.system.entity.SysPost;
import com.laoxiang.modules.system.entity.dto.PageDTO;
import com.laoxiang.modules.system.entity.vo.QueryPostVO;
import com.laoxiang.modules.system.service.SysPostService;
import com.laoxiang.utils.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * 岗位信息表(SysPost)表控制层
 *
 * @author db
 * @since 2023-09-03 22:43:44
 */
@RestController
@RequestMapping("/sysPost")
@Api(tags = "岗位管理")
public class SysPostController  {
    /**
     * 服务对象
     */
    @Resource
    private SysPostService sysPostService;


    @ApiOperation(httpMethod = "GET",value = "按条件查询获得岗位列表")
    @GetMapping("/getPostList")
    public ResponseResult getPostList(Integer pageNum, Integer pageSize, QueryPostVO queryPostVO){
        PageDTO posts = sysPostService.getPosts(pageNum, pageSize, queryPostVO);
        return ResponseResult.okResult(posts);
    }

    @ApiOperation(httpMethod = "GET",value = "获得全部岗位列表")
    @GetMapping("/getAllPosts")
    public ResponseResult getAllPosts(){
        List<SysPost> postList = sysPostService.getPostList();
        return ResponseResult.okResult(postList);
    }

    @ApiOperation(httpMethod = "POST",value = "新增岗位")
    @PostMapping("/addPost")
    public ResponseResult addPost(@RequestBody SysPost sysPost){
        sysPostService.addPost(sysPost);
        return ResponseResult.okResult();
    }

    @ApiOperation(httpMethod = "GET",value = "通过岗位Id获得岗位信息")
    @GetMapping("/getPostById/{postId}")
    public ResponseResult getPostById(@PathVariable("postId") Long postId){
        SysPost sysPost = sysPostService.getPostById(postId);
        return ResponseResult.okResult(sysPost);
    }

    @ApiOperation(httpMethod = "PUT",value = "更新岗位信息")
    @PutMapping("/updatePost")
    public ResponseResult updatePost(@RequestBody SysPost sysPost){
        sysPostService.updatePost(sysPost);
        return ResponseResult.okResult();
    }

    @ApiOperation(httpMethod = "DELETE",value = "删除岗位")
    @DeleteMapping("/deletePostById/{postId}")
    public ResponseResult deletePostById(@PathVariable("postId") Long postId){
        sysPostService.deletePostById(postId);
        return ResponseResult.okResult();
    }

    @ApiOperation(httpMethod = "DELETE",value = "批量删除岗位")
    @DeleteMapping("/batchDeletePost/{postIds}")
    public ResponseResult batchDeletePost(@PathVariable("postIds") List<Long> postIds){
        sysPostService.batchDeletePost(postIds);
        return ResponseResult.okResult();
    }
}

